package main

import (
	"net/http"
	"bytes"
	"net/url"
	"goBasic/ketanx/help"
	"io/ioutil"
	"fmt"
)

var urlstr string = "https://www.toutiao.com/search/suggest/initial_page/"
var urlstr2 string = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getWeatherbyCityName"

func main()  {

	//test1()

	test2()



}

/**
buffer := bytes.NewBufferString("")
 http.Post("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName",
  "application/x-www-form-urlencoded", buffer)
 */

 /*
 李旭 6-5 14:18
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getWeatherbyCityName
 */
func test1()  {
	//构建参数
	param := urlstr2.Values{
		"theCityName":{"北京"},
	}

	//参数转换成body
	buffer := bytes.NewBufferString(param.Encode())

	//发起post请求
	rep, err := http.Post(urlstr2, "application/x-www-form-urlencoded", buffer)
	help.CheckError(err)


	if rep.StatusCode == 200 {

		bs, err := ioutil.ReadAll(rep.Body)
		help.CheckError(err)
		fmt.Println(string(bs))

	} else {

	}
}

func test2()  {
	//参数
	param := urlurl.Values{
		"theCityName":{"北京"},
	}

	//转成buffer
	buffer := bytes.NewBufferString(param.Encode())
	//发post请求
	resp,err := http.Post(urlstr2,  "application/x-www-form-urlencoded", buffer)
	help.CheckError(err)

	if resp.StatusCode == 200 {
		bs, err := ioutil.ReadAll(resp.Body)
		help.CheckError(err)
		fmt.Println(string(bs))

	} else {
		fmt.Println("StatusCode:", resp.StatusCode)

	}



}